package jdbcinterface;

import java.sql.*;

import rmi.RemoteMetaData;
import rmi.RemoteResultSet;
import rmi.ResultSetAdapter;


public class GoggleResultSet extends ResultSetAdapter {
	private RemoteResultSet rrs;

	public GoggleResultSet(RemoteResultSet s) {
		rrs = s;
	}
	public RemoteResultSet getRrs()
	{
		return rrs;
	}

	public boolean next() throws SQLException {
		try {
			return rrs.next();
		}
		catch (Exception e) {
			throw new SQLException(e.toString() );
		}
	}

	public int getInt(String fldname) throws SQLException {
		try {
			return rrs.getInt(fldname);
		}
		catch (Exception e) {
			throw new SQLException(e.toString() );
		}
	}

	public String getString(String fldname) throws SQLException {
		try {
			return rrs.getString(fldname);
		}
		catch (Exception e) {
			throw new SQLException(e.toString() );
		}
	}

	public float getFloat(String fldname) throws SQLException {
		try {
			return Float.valueOf( rrs.getString(fldname));
		}
		catch (Exception e) {
			throw new SQLException(e.toString() );
		}
	}
	
	
	//====================================================================================
	
	public int getInt(int index) throws SQLException {
		try {
			return rrs.getInt(index);
		}
		catch (Exception e) {
			throw new SQLException(e.toString() );
		}
	}

	public String getString(int index) throws SQLException {
		try {
			return rrs.getString(index);
		}
		catch (Exception e) {
			throw new SQLException(e.toString() );
		}
	}
	
	public float getFloat(int index) throws SQLException {
		try {
			return Float.valueOf( rrs.getString(index));
		}
		catch (Exception e) {
			throw new SQLException(e.toString() );
		}
	}

	public Date getDate ( int index ) throws SQLException {
		try {
			return Date.valueOf ( rrs.getString( index )) ;
		}catch ( Exception e ) { 
			throw new SQLException ( e.toString () ) ; 
		}
		
	}

	public Date getDate ( String name ) throws SQLException {
		try {
			return Date.valueOf ( rrs.getString( name )) ;
		}catch ( Exception e) { 
			throw new SQLException ( e.toString ()) ;
		}
	}
	
	public boolean getBoolean ( int index ) throws SQLException {
		try {
			return Boolean.valueOf ( rrs.getString( index )) ;
		}catch ( Exception e ) { 
			throw new SQLException ( e.toString () ) ; 
		}
		
	}

	public boolean getBoolean ( String name ) throws SQLException {
		try {
			return Boolean.valueOf ( rrs.getString( name )) ;
		}catch ( Exception e) { 
			throw new SQLException ( e.toString ()) ;
		}
	}
	
	public Timestamp getTimestamp ( int index ) throws SQLException {
		try {
			return Timestamp.valueOf ( rrs.getString( index )) ;
		}catch ( Exception e ) { 
			throw new SQLException ( e.toString () ) ; 
		}
		
	}

	public Timestamp getTimestamp ( String name ) throws SQLException {
		try {
			return Timestamp.valueOf ( rrs.getString( name )) ;
		}catch ( Exception e) { 
			throw new SQLException ( e.toString ()) ;
		}
	}
	
	
	public ResultSetMetaData getMetaData() throws SQLException {
		try {
			RemoteMetaData rmd = rrs.getMetaData();
			return new GoggleMetaData(rmd);
		}
		catch (Exception e) {
			throw new SQLException(e.toString() );
		}
	}

	public void close() throws SQLException {
		try {
			rrs.close();
		}
		catch (Exception e) {
			throw new SQLException(e.toString() );
		}
	}
}

